package com.zxl.grocery.common.constant.dictmap.factory;


import com.zxl.grocery.common.constant.dictmap.base.AbstractDictMap;
import com.zxl.grocery.common.constant.dictmap.base.SystemDict;
import com.zxl.grocery.common.exception.BizExceptionEnum;
import com.zxl.grocery.common.exception.BussinessException;

/**
 * 字典的创建工厂
 * Created by Lzx on 2017/7/30
 */
public class DictMapFactory {

    private static final String basePath = "com.zxl.grocery.common.constant.dictmap.";

    /**
     * 通过类名创建具体的字典类
     */
    public static AbstractDictMap createDictMap(String className) {
        if("SystemDict".equals(className)){
            return new SystemDict();
        }else{
            try {
                Class<AbstractDictMap> clazz = (Class<AbstractDictMap>) Class.forName(basePath + className);//以后研究 参考：http://blog.csdn.net/truong/article/details/34928645
                return clazz.newInstance();//使用类加载机制初始化一个类，生成一个实例
            } catch (Exception e) {
                throw new BussinessException(BizExceptionEnum.ERROR_CREATE_DICT);//创建字典失败
            }
        }
    }
}
